<?php
namespace Qwadmin\Model;

class DomainModel extends \Think\Model{
    public function lists($map ,$page = 1){
        $count = M("domain")->where($map)->count("id");
        $pagesize = 20 ;
        $offset = $pagesize * ($page - 1); //计算记录偏移量
        $pagebar = new \Think\Page($count , $pagesize);
        $list  = M("domain")->order("status asc , id desc")
                            ->where($map)
                            ->limit($offset . ',' . $pagesize)
                            ->select();
        return [
            'page'  => $pagebar->show(),
            'list'  => $list
        ];
    }
    
    /**
     *  批量添加数据方法
     *  @param array $data  批量数据数组
     *  @return int 受影响行数
     */
    public function insertAll($data){
        $rows = M("domain")->addAll($data);
        return $rows;
    }
    
    /**
     *  获取指定层域名
     *  @param int $level 指定层
     */
    public function getDomain($level){
       $data =  M("domain")->field('domain')->where(['status' => 1 , 'level' => $level])->find();
       return $data['domain'];
    }
    
}
